

package com.thxrinfo.stop.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.thxrinfo.stop.api.entity.RegionRoad;
import com.thxrinfo.stop.service.RegionRoadService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;


/**
 * 路边车场区域
 *
 * @author ct
 * @date 2023-02-06 15:58:09
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/regionroad" )
@Tag(name = "路边车场区域管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class RegionRoadController {

    private final RegionRoadService regionRoadService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param regionRoad 路边车场区域
     * @return
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('stop_regionroad_get')" )
    public R getRegionRoadPage(Page page, RegionRoad regionRoad) {
        return R.ok(regionRoadService.getList(page, regionRoad));
    }

	@Operation(summary = "获取全部路边车场区域", description = "获取全部路边车场区域")
	@GetMapping("/all" )
	@PreAuthorize("@pms.hasPermission('stop_regionroad_get')" )
	public R getAll(Long parkId) {
		QueryWrapper<RegionRoad> wrapper = new QueryWrapper<>();
		wrapper.orderBy(true,false, "update_time");
		if (parkId == null) {
			parkId = -1L;
		}
		wrapper.eq("park_id", parkId);

		return R.ok(regionRoadService.list(wrapper));
	}

    /**
     * 通过id查询路边车场区域
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('stop_regionroad_get')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(regionRoadService.getById(id));
    }

    /**
     * 新增路边车场区域
     * @param regionRoad 路边车场区域
     * @return R
     */
    @Operation(summary = "新增路边车场区域", description = "新增路边车场区域")
    @SysLog("新增路边车场区域" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('stop_regionroad_add')" )
    public R save(@RequestBody RegionRoad regionRoad) {
        return R.ok(regionRoadService.save(regionRoad));
    }

    /**
     * 修改路边车场区域
     * @param regionRoad 路边车场区域
     * @return R
     */
    @Operation(summary = "修改路边车场区域", description = "修改路边车场区域")
    @SysLog("修改路边车场区域" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('stop_regionroad_edit')" )
    public R updateById(@RequestBody RegionRoad regionRoad) {
        return R.ok(regionRoadService.updateById(regionRoad));
    }

    /**
     * 通过id删除路边车场区域
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id删除路边车场区域", description = "通过id删除路边车场区域")
    @SysLog("通过id删除路边车场区域" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('stop_regionroad_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(regionRoadService.removeById(id));
    }

}
